<template>
  <div>
    <el-table
        v-loading="loading"
        :data="tableData"
        border
        style="width: 100%">
      <el-table-column
          fixed
          prop="id"
          label="编号"
          width="150">
      </el-table-column>
      <el-table-column
          prop="name"
          label="商品名称"
          width="120">
      </el-table-column>
      <el-table-column
          prop="categoryId"
          label="类别"
          width="120">
      </el-table-column>
      <el-table-column
          prop="iconUrl"
          label="图片"
          width="120">
        <template slot-scope="scope">
          <img :src="scope.row.iconUrl" min-width="150" height="70"/>
        </template>
      </el-table-column>
      <el-table-column
          prop="detail"
          label="商品详情"
          width="120">
      </el-table-column>
      <el-table-column
          prop="specParam"
          label="规格参数"
          width="120">
      </el-table-column>
      <el-table-column
          prop="price"
          label="价格"
          width="120">
      </el-table-column>
      <el-table-column
          prop="stock"
          label="库存"
          width="120">
      </el-table-column>
      <el-table-column
          prop="status"
          label="商品状态"
          width="120">
      </el-table-column>
      <el-table-column
          prop="isHot"
          label="是否热销"
          width="120">
      </el-table-column>
<!--      <el-table-column-->
<!--          prop="created"-->
<!--          label="创建时间"-->
<!--          width="120">-->
<!--      </el-table-column>-->
<!--      <el-table-column-->
<!--          prop="updated"-->
<!--          label="更新时间"-->
<!--          width="120">-->
<!--      </el-table-column>-->
      <el-table-column
          fixed="right"
          label="操作"
          width="100">
        <template slot-scope="scope">
          <el-button @click="edit(scope.row)" type="text" size="small">修改</el-button>
          <el-button @click="del(scope.row)" type="text" size="small">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
        background
        layout="prev, pager, next"
        page-size="5"
        :total="total"
        @current-change="page">
    </el-pagination>
  </div>
</template>

<script>
export default {
  methods: {
    edit(row) {
      // this.$router.push({
      //   path:'/PageThree',
      //   query:{
      //     id:row.id
      //   }
      // })
    },
    del(row){
      const _this=this;
      this.$confirm('此操作将永久删除该商品, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        axios.post('http://localhost:8181/product/deleteProduct/'+row.id).then(function(resp){
          if(resp.data==0){
            _this.$message.error('删除失败!');
          }else{
            _this.$message({
              type: 'success',
              message: '删除成功!'
            });
            window.location.reload();
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        });
      });
    },
    page(currentPage){
      const _this=this;
      axios.get('http://localhost:8181/product/findAllGoods/'+currentPage+'/'+5).then(function(resp){
        _this.tableData=resp.data.data
        _this.total=resp.data.totalNum
        _this.loading=false
      })
    }
  },
  created() {
    const _this=this;
    axios.get('http://localhost:8181/product/findAllGoods/'+1+'/'+5).then(function(resp){
      _this.tableData=resp.data.data
      _this.total=resp.data.totalNum
      _this.loading=false
    })
  },
  data() {
    return {
      total:null,
      tableData:null,
      loading: true
    }
  }
}
</script>

<style scoped>

</style>